# Input parameter {#inputs}
```{r setup1, echo = F, message=FALSE, warning=FALSE}
rm(list = ls())  # delete everything that is in R's memory
knitr::opts_chunk$set(message = FALSE)
# all the figures will be 6.5 x 4 inches and centered in the text.
knitr::opts_chunk$set(fig.width=6.5, 
                      fig.height=4, 
                      fig.align="center"
                      )

options(scipen=1000) # removal of scientific notation
path <- "C:/Users/PouwelsXGLV/Documents/Maastricht/Eribulin CEA/Model final_Gamma/" #set location of model, to adapt!
setwd(paste(path,"report", sep = "")) # set working directory to File Source
      
#load package
library(rms)
library(survival)
library(muhaz)
library(survminer)
library(ggplot2)
library(data.table)
library(printr)
library(dplyr)
library(flexsurv)
library(tidyverse)
library(scales)
library(matrixStats)
library(reshape2)

# load functions
source(paste(path,"R/01_fun_analyses.R", sep = "")) 
# load model inputs
load(paste(path,"data/01_model_inputs.R", sep = ""))
```

This section describes the parameter values populating the deterministic cost-effectiveness model. These parameters are stored in the *01_model_inputs.R* file under the `data` folder. The *01_model_inputs.R* contains all required model inputs for the deterministic analysis (*params_det* list) and the parameters relating to the model structure and assumptions of the model. To load model inputs, use the `load` function. Table \@ref(tab:inputs) shows the model inputs, their R object name and their value as used in the deterministic model. Health state costs are assumed to be treatment independent, but the model allows to specify model parameters as treatment dependent values. Parameters with a *R name* finishing with `.trt` concern eribulin while the ones finishing with `.comp` concern non-eribulin chemotherapy. The estimation of the different parameters is explained in the next sections.  

Table: (\#tab:inputs) Overview of the input parameters of the model

|           Parameter                |  R name     |   Value       |
|:-----------------------------------|:------------|:--------------|
|Mean age of patients at treatment initiation| `startage` | `r round(params_det$startage,0)`|
|Time horizon                        | `n.t`       | `r n.t` years |
|Health state names                  | `v.n`       | `r v.n`*      |
|Annual discout rate effects         | `d.e`       | `r d.e`       |
|Annual discout rate costs           | `d.c`       | `r d.c`       |
|**Treatment effectiveness**         |             |               |
|Selected distribution OS            | `s.mod.OS`  |  `r params_det$s.mod.OS`|
|Survival probabilities for OS, eribulin| `s.OS.trt`|  |
|Survival probabilities for OS, non-eribulin| `s.OS.comp`||
|Selected distribution PFS            | `s.mod.PFS`  |  `r params_det$s.mod.PFS`|
|Survival probabilities for PFS, eribulin| `s.PFS.trt`|  |
|Survival probabilities for PFS, non-eribulin| `s.PFS.comp`||
|Selected distribution TTD            | `s.mod.TTD`  |  `r params_det$s.mod.TTD`|
|Survival probabilities for TTD, eribulin| `s.TTD.trt`|  |
|Survival probabilities for TTD, non-eribulin| `s.TTD.comp`||
|Probability AE - eribulin           | `e.AE.prob.trt`|`r round(params_det$e.AE.prob.trt,2)`|
|Probability AE - non-eribulin       | `e.AE.prob.comp`|`r round(params_det$e.AE.prob.comp,2)`|
|Length in days AE - eribulin       | `e.AE.length.trt`|`r round(params_det$e.AE.length.trt,2)`|
|Length in days AE - non-eribulin   |`e.AE.length.comp`|`r params_det$e.AE.length.comp`|
|**Utility values**                  |             |               |
| - Progression-free health state    | `u.PFS`     |  `r params_det$u.PFS`|
| - Progressed disease health state  | `u.PD`      |  `r params_det$u.PD`|
| - Time-to-treatment discontinuation health state*| `u.TTD`|  `r params_det$u.TTD`|
| - Death health state               | `u.D`       |  `r params_det$u.D` |
| - Disutility AE                    | `u.AE`      |  `r params_det$u.AE`|
|**Resource use and costs**          |             |               |
|Preparation costs intravenous chemotherapy| `c.prepa`| &euro;`r round(params_det$c.prepa,0)`|
|Administration costs intravenous chemotherapy| `c.ivadm`| &euro;`r round(params_det$c.ivadm,0)`|
|Acquisition costs eribulin          | `c.PFS.systhx.trt`| &euro;`r round(params_det$c.PFS.systhx.trt,0)`|
|Acquisition costs non-eribulin, treatments administered on day 1 of a 21 day cycle| `c.PFS.systhx.comp_1`|&euro;`r round(params_det$c.PFS.systhx.comp_1,0)`|
|Acquisition costs non-eribulin, treatments administered on days 1 to 14 or days 1 and 8 of a 21 day cycle| `c.PFS.systhx.comp_2`|&euro;`r round(params_det$c.PFS.systhx.comp_2,0)`|
|Acquisition costs non-eribulin, treatments administered once a week or daily| `c.PFS.systhx.comp_3`|&euro;`r round(params_det$c.PFS.systhx.comp_3,0)`|
|Acquisition costs non-eribulin, treatments administered on on days 1 of a 28 days cycle| `c.PFS.systhx.comp_4`|&euro;`r round(params_det$c.PFS.systhx.comp_4,0)`|
|Acquisition costs non-eribulin, treatments administered on on days 1 to 14 or days 1 and 8 of a 28 days cycle| `c.PFS.systhx.comp_5`|&euro;`r round(params_det$c.PFS.systhx.comp_5,0)`|
|Acquisition costs non-eribulin, treatments administered on on days 1 and 15 of a 28 days cycle| `c.PFS.systhx.comp_6`|&euro;`r round(params_det$c.PFS.systhx.comp_6,0)`|
|Proportion of non-eribulin patients receiving IV administration, treatments administered on day 1 of a 21 day cycle| `ru.PFS.prop.comp_1`|`r round(params_det$ru.PFS.prop.comp_1,2)`|
|Proportion of non-eribulin patients receiving IV administration, treatments administered on days 1 to 14 or days 1 and 8 of a 21 day cycle| `ru.PFS.prop.comp_2`|`r round(params_det$ru.PFS.prop.comp_2,2)`|
|Proportion of non-eribulin patients receiving IV administration, treatments administered once a week or daily| `ru.PFS.prop.comp_3`|`r round(params_det$ru.PFS.prop.comp_3,2)`|
|Proportion of non-eribulin patients receiving IV administration, treatments administered on on days 1 of a 28 days cycle| `ru.PFS.prop.comp_4`|`r round(params_det$ru.PFS.prop.comp_4,2)`|
|Proportion of non-eribulin patients receiving IV administration, treatments administered on on days 1 to 14 or days 1 and 8 of a 28 days cycle| `ru.PFS.prop.comp_5`|`r round(params_det$ru.PFS.prop.comp_5,2)`|
|Proportion of non-eribulin patients receiving IV administration, treatments administered on on days 1 and 15 of a 28 days cycle| `ru.PFS.prop.comp_6`|`r round(params_det$ru.PFS.prop.comp_6,2)`|
|PF health state costs - monitoring (weekly)| `c.PFS.mon.trt` & `c.PFS.mon.comp`|&euro;`r round(params_det$c.PFS.mon.trt,0)`|
|PF health state costs - radiotherapy (weekly)| `c.PFS.radio.trt` & `c.PFS.radio.comp`|&euro;`r round(params_det$c.PFS.radio.trt,0)`|
|PF health state costs - surgery (weekly)| `c.PFS.surg.trt` & `c.PFS.surg.comp`|&euro;`r round(params_det$c.PFS.surg.trt,0)`|
|PF health state costs - hospitalisation (weekly)| `c.PFS.hosp.trt` & `c.PFS.hosp.comp`|&euro;`r round(params_det$c.PFS.hosp.trt,0)`|
|PD health state - weekly systemic treatment costs| `c.PD.systhx.trt` & `c.PD.systhx.comp`|&euro;`r round(params_det$c.PD.systhx.trt,0)`|
|PD health state costs - monitoring (weekly)| `c.PD.mon.trt` & `c.PD.mon.comp`|&euro;`r round(params_det$c.PD.mon.trt,0)`|
|PD health state costs - radiotherapy (weekly)| `c.PD.radio.trt` & `c.PD.radio.comp`|&euro;`r round(params_det$c.PD.radio.trt,0)`|
|PD health state costs - surgery (weekly)| `c.PD.surg.trt` & `c.PD.surg.comp`|&euro;`r round(params_det$c.PD.surg.trt,0)`|
|PD health state costs - hospitalisation (weekly)| `c.PD.hosp.trt` & `c.PD.hosp.comp`|&euro;`r round(params_det$c.PD.hosp.trt,0)`|
|Disease-related costs incurred in the last year of life|`c.related`|Age dependent, shown lower|
|Disease-unrelated costs incurred in the last year of life|`c.unrelated`|Age dependent, shown lower|
|Patient and family costs incurred by an outpatient visits for IV administration and AE hospitalisation |`c.ptfam.visit`|&euro;`r round(params_det$c.ptfam.visit,0)`|
|Abbreviations: AE = adverse events, IV = intravenous, OS = overall survival, PD = progressed disease, PF = progression-free, PFS = progression-free survival, TTD = time to treatment discontinuation|||
|* TTD health state is only used to calculate chemotherapy costs in the PFS health state|||

## Effectiveness, survival models: OS, PFS, TTD
The parametric survival models are estimated for overall survival (OS), progression-free survival (PFS), and time-to-treatment discontinuation (TTD). Since individual patient level data may not be released, the parametric survival models are estimated using the `surv_pred_det` function which is loaded through the *01_fun_analyses.R* file (an annotated version of the function can be found in the`R` folder). The function is printed in the following window and is applied to the `df.os`, `df.pfs`, and `df.ttd` object to obtain separate estimations of survival probabilities for OS, PFS, and TTD for each treatment arm.

```{r survival model estimation, echo = T}
print.function(surv.pred_det)
```

The `surv_pred_det` function results in a list containing two dataframes. The first dataframe in the list contains the survival probabilities of the eribulin group while the second contains the survival probabilities of the non-eribulin group (for OS, we named them `s.OS.trt` and `s.OS.comp` for the  eribulin and non-eribulin groups respectively). Each data frame of the list contains the following distributions in the following order: exponential, Weibull, Gompertz, log normal, log-logistic, gamma, and generalised gamma.

## Utility values
As described in the manuscript, utility values were obtained from published literature [@VANKAMPEN2017]. We literally took over these utility values from the literature for the progression-free and progressed disease health states, hence, we do not extensively describe them here again (Table \@ref(tab:inputs)).

## Chemotherapy costs eribulin
The costs of eribulin included vial waste. This means that all the administered doses of eribulin were sorted according to the numbers of vials administered to patients.  There are 2ml and 3ml vials of eribulin. A weighted average was calculated by multiplying the costs of each vial combination by the number of time each vial combination was administered. The `ru.eri.vials` object (saved in *01_model_inputs.R*) provides the number of time each vial combination has been administered and how much each combination costs. The calculation is detailed in the next R code window below.

```{r diri.trt, echo = T}
#ru.eri.vials contains 3 columns:
##'vial' column identifies the vial combinations
###vials = 0, no administration
###vials = 1, 1 vial of 2mg
###vials = 2, 1 vial of 3mg
###vials = 3, 1 vial of 3mg & 1 vial of 2mg
###vials = 4, 2 vials of 3mg
##'numbers' column contain how much time the vials combination has been administered
##'costs' column contain the costs of each vials combination

##costs of one eribulin administration is calculated by the weighted average
##based on the 'numbers' and 'costs' columns (matrices multiplication)
c.eri <- t(ru.eri.vials$costs) %*% ru.eri.vials$number/sum(ru.eri.vials$numbers)
c.eri <- c.eri[1,1]
```

## Chemotherapy costs non-eribulin
The `df.systhx.comp` object (*01_model_inputs.R*) provides an overview of the treatment administered to the non-eribulin group. In order to obtain one estimate per administration schedule, as described in Table \@ref(tab:inputs), treatments were grouped by administration schedule. Aggregated costs per administration schedule were obtain through the `Systhx_PFS` function (*01_fun_analyses.R*). This formula calculates both deterministic and probabilitistic costs estimates in one go. The `c.aggthx.comp` object (*01_model_inputs.R*) contains the aggregated deterministic costs per aministration schedule, the `df.systhx.comp_prob` object (*01_model_inputs.R*) contains the aggregated probabilistic costs per aministration schedule, which are respectively used in the deterministic and probabilistic analyses. These estimates are calculated based on the mean administered dose, the proportion of patients receiving each treatment, and the dose intensity. These estimates are obtained by using the below-described `Systhx_PFS` function.
```{r, echo = T}
print.function(Systhx_PFS)
``` 

###Proportion of patients receiving intravenous administration in the non-eribulin group
The proportion of patients receiving intravenous administration was calculated based on the `df.systhx.comp` object (*01_model_inputs.R*). These proportions are summarised in the `ru.ivadm.comp` object (*01_model_inputs.R*). Patients receiving capecitabine, lapatinib, and neratinib were not taken into account in these calculations because these treatments are administered orally.

```{r adm costs comp, echo = T, message=FALSE, warning = FALSE}
#determine how much patients will incur intravenous (IV) administration 
#and preparation costs in the non-eribulin arm
df <- df.systhx.comp
#remove patients who do not have IV administration costs
df <- df[-c(which(grepl("Cape", df$Thxnames) == TRUE)),] #remove patients who received capecitabine 
df <- df[-c(which(grepl("Lapa", df$Thxnames) == TRUE)),] #remove patients who received lapatinib 
df <- df[-c(which(grepl("Nera", df$Thxnames) == TRUE)),] #remove patients who received neratinib 
df <- df[-which(duplicated(cbind(df$Combinames, df$weeks))),]#remove duplicates
#to avoid considering patients receiving 2 treatment on the same day twice

#number of patients receiving each administration schedule
ru.ivadm.comp <- aggregate(Numpt ~ weeks, df, sum) 
#proportion of patients receiving IV adm and preparation costs per administration schedule
ru.ivadm.comp$prop <- ru.ivadm.comp$Numpt/n.group  
rm(df)
```

## Disease-related health care costs, last year of life
Disease-related health care costs were not estimated based on the SONABRE registry but were obtained from the PAID tool v1.1 [@vanBaal2011]. These estimates are age-dependent and are the following (yearly costs): 
```{r, echo = T}
params_det$c.related #provided in 01_model_inputs.R
```

## Disease-unrelated health care costs, additional year of life
Disease-unrelated health care costs were not estimated based on the SONABRE registry but were obtained from the PAID tool v1.1 [@vanBaal2011]. These estimates are age-dependent and are the following (yearly costs):
```{r, echo = T}
params_det$c.unrelated #provided in 01_model_inputs.R
```

## Patient and family costs
Patient and family costs (`c.ptfam.visit` object in *01_model_inputs.R*) were calculated based on the Dutch guidelines for economic evaluations in health care [@ZIN2016], assuming a mean distance of 7 km between a patient's house and the hospital, a cost per km of &euro;0.19 and &euro;3 of parking costs. Since a visit incurs going and coming back from the hospital, the travel costs were doubled. The calculation is provided in the following window. This parameter is already included in the `params_det` list(i.e. `params_det$c.ptfam.visit`).

```{r, echo = T}
c.ptfam.visit <- 2*7*0.19+3
```
